/**
 * Created by wdj on 15/11/13.
 */
;(function(hybrid){

    hybrid.utils = {
        extend: function(a, b){
            for (var k in b){
                if(b.hasOwnProperty(k))a[k] = b[k];
            }
            return a;
        },
        isArray: function(arr){
            return Object.prototype.toString.apply(arr) === '[object Array]';
        },
        forEach: function(obj, callback){
            if (typeof obj !== 'object') return;
            if (!callback) return;
            var i, prop;
            if (this.isArray(obj) || obj instanceof Dom7) {
                // Array
                for (i = 0; i < obj.length; i++) {
                    callback(i, obj[i]);
                }
            }
            else {
                // Object
                for (prop in obj) {
                    if (obj.hasOwnProperty(prop)) {
                        callback(prop, obj[prop]);
                    }
                }
            }
        },
        unique: function(arr){
            var unique = [];
            for (var i = 0; i < arr.length; i++) {
                if (unique.indexOf(arr[i]) === -1) unique.push(arr[i]);
            }
            return unique;
        },
        parseUrlQuery: function(url){
            var query = {}, i, params, param;
            if (url.indexOf('?') >= 0) url = url.split('?')[1];
            else return query;
            params = url.split('&');
            for (i = 0; i < params.length; i++) {
                param = params[i].split('=');
                query[param[0]] = param[1];
            }
            return query;
        }
    };

})(Hybrid || {});
